<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@ include file="/WEB-INF/component/commonTagLib.jsp"%>
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title></title>
    <%@ include file="/WEB-INF/component/commonCSS.jsp" %>

    <!--[if lt IE 9]>
        <script src="lib/js/html5shiv.min.js"></script>
        <script src="lib/js/respond.min.js"></script>
    <![endif]-->

</head>
<body class="skin-blue-light sidebar-mini fixed skin-blue-light-frame">
    <section class="content-header">
        <h1><spring:message code="message.lable.compgroupSTDsee"/></h1>
        <ol class="breadcrumb">
            <li><a href="${ctx}/home.jsp"><i class="fa fa-home"></i><spring:message code="message.lable.first"/></a></li>
            <li class="active"><a href="#"><spring:message code="message.lable.StdManage"/></a></li>
            <li class="active"><a href="#"><spring:message code="message.lable.compgroupStd"/></a></li>
        </ol>
    </section>
    
   <section class="content">
        <div class=" box box-success">
            <div class="box-body">
             <form action="${ctx}/stdCompGroup/exportExcel.html" id="exportExcel" method="post">
             <input id="fileName" name="fileName" type="hidden" value="<spring:message code="message.lable.compGroupxls"/>" />
                    <div class="input">
                    <div class="textalign1"><spring:message code="message.listForm.jiTuanMingCheng"/>：</div>
                    <div class="boxinput">
                        <input type="text" class="textinput" id="searchName" name="compGroupName" placeholder="<spring:message code="message.listForm.jiTuanMingCheng"/>" />
                    </div>
                    <div class="textalign1"><spring:message code="message.listForm.jiTuanBianMa"/>：</div>
                    <div class="boxinput">
                        <input type="text" class="textinput" id="searchCode" name="compGroupCode" placeholder="<spring:message code="message.listForm.jiTuanBianMa"/>" />
                    </div>
                    <div class="textalign1"><spring:message code="message.lable.status"/>：</div>
                    <div class="boxinput">
                       <select id="status" name="status" class="textinput">
                            <option value="" ><spring:message code="message.select.option"/></option>
                            <option value="1" ><spring:message code="message.button.start"/></option>
                            <option value="0" ><spring:message code="message.button.stop"/></option>
                           </select>
                     </div>
                     <div class="textalign1" >
                    <button id="selectGroup" type="button" class="btn btn-success btn-sm" onclick="search();"> <spring:message code="message.button.seachSpacing"/></button>
                </div>
                </div>
                </form>
            </div>
        </div>

        <table class="jqgrid" id="gridlist"></table>
           <div id="gridpage"></div>

        <div class=" box box-warning bottongroup">

             <ms:btn url="/stdCompGroup/add.html"><label id="addNew" class="btn btn-default btn-sm"><spring:message code="message.button.addSpacing"/></label></ms:btn>
             <ms:btn url="/stdCompGroup/enable.html"><label id="allStart" class="btn btn-default btn-sm"  onclick="batchChangeStatus(1)"><spring:message code="message.button.startSpacing"/></label></ms:btn>
             <ms:btn url="/stdCompGroup/disable.html"><label id="allDelete" class="btn btn-default btn-sm" onclick="batchChangeStatus(0)"><spring:message code="message.button.stopSpacing"/></label></ms:btn>
             <label onclick="exportExcel();" class="btn btn-default btn-sm"><spring:message code="message.lable.daoChu"/></label>
        </div>
        
         <div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header bg-primary">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                        <h5 class="modal-title" id="exampleModalLabel"><spring:message code="message.lable.compgroupSTDadd"/><spring:message code="message.lable.compgroupSTDedit"/> </h5>
                    </div>
                    <div class="modal-body">
                     <form>
                     
                      <div class="form-group form-group-xs" style="display:none;">
                        <label for="compGroupCode" class=" control-label"><span style="color:red">*&nbsp;</span><spring:message code="message.listForm.jiTuanBianMa"/>：</label>
                        <div class="">
                            <input type="text" class="form-control" id="compGroupCode" placeholder="<spring:message code="message.listForm.jiTuanBianMa"/>" maxlength="20" >
                        </div>
                    </div> 
                   <!--  <input type="hidden" name="compGroupCode" id="compGroupCode" /> -->
                    <div class="form-group form-group-xs">
                        <label for="compGroupName" class=" control-label"><span style="color:red">*&nbsp;</span><spring:message code="message.listForm.jiTuanMingCheng"/>：</label>
                        <div class="">
                            <input type="text" class="form-control" id="compGroupName" placeholder="<spring:message code="message.listForm.jiTuanMingCheng"/>" maxlength="100" >
                        </div>
                    </div>
                    <div class="form-group form-group-xs">
                        <label for="compGroupShortname" class=" control-label"><spring:message code="message.listForm.jiTuanJianCheng"/>：</label>
                        <div class="">
                            <input type="text" class="form-control" id="compGroupShortname" placeholder="<spring:message code="message.listForm.jiTuanJianCheng"/>" maxlength="100" >
                        </div>
                    </div>
                    <div class="form-group form-group-xs">
                        <label for="remark" class=" control-label"><spring:message code="message.lable.remark"/>：</label>
                        <div class="">
                            <input type="text" class="form-control" id="remark" placeholder="<spring:message code="message.lable.remark"/>" maxlength="100" >
                        </div>
                    </div>
                    </form>
                    </div>
                    <div class="modal-footer">
                        <button type="button" onclick="save();" class="btn btn-primary btn-sm"><spring:message code="message.button.saveSpacing"/></button>
                        <button type="button" class="btn btn-danger btn-sm" data-dismiss="modal"><spring:message code="message.button.closeSpacing"/></button>
                    </div>
                </div>
            </div>
        </div>
 
    </section>
   <%@ include file="/WEB-INF/component/commonJS.jsp"%>
    <script type="text/javascript">
    
    //获取当前页数,给新增修改弹窗用
    function currentPage(){
        return $("#gridlist").jqGrid('getGridParam','page');  
    } 
    
   
    //绑定回车
    $('#searchCode,#searchName,#status').bind('keydown', function(event) {
        if (event.keyCode == "13") {        //13 位电脑上回车键的位置代码
            $('#selectGroup').click();
        }
    }); 
  
    $("#searchName").focus();//加载页面光标在第一个查询框内
    
    //查询
    function search(page) {
        var Code = $.trim($("#searchCode").val());
        var Name = $.trim($("#searchName").val());
        var status = $("#status").val();
        $("#gridlist").jqGrid('setGridParam',{  
            mtype: "POST",
            datatype:'json',
            postData:{"compGroupCode":Code, "compGroupName":Name,"status":status},
            page : (page || 1)
        }).trigger("reloadGrid"); //重新载入  
    }
    
    
        $(function () {
          /*   $('#addNew').click(function () {
                 $.HN.dialog.open({
                     id:"add",
                     title:"<spring:message code="message.lable.compgroupSTDadd"/>",
                     url:" ${ctx}/stdCompGroup/compGroupAdd.html",
                     width:"800px",
                     height:"300px"
                 }); */
                //location="compGroupAdd.html"
         //   });
            
          
            $("#gridlist").jqGrid({
                url: "stdCompGroupList.html",
                mtype: "POST",
                datatype: "json",
                autowidth: true,
                height: 270,
                colNames: ['<spring:message code="message.jqGrid.cz"/>',
                           'compGroupId' ,
                           '<spring:message code="message.listForm.jiTuanBianMa"/>',
                           '<spring:message code="message.listForm.jiTuanMingCheng"/>',
                           '<spring:message code="message.listForm.jiTuanJianCheng"/>',
                           '<spring:message code="message.lable.remark"/>',
                           '<spring:message code="message.lable.status"/>'
                           ],
                colModel: [
                    { name: 'operate', align:"center",width: 70,sortable: false,formatter : function(val, opts, rowdata) {
                        var str="";
                        str += "<ms:btn url='/stdCompGroup/edit.html'><a href=\"javascript:edit('"+rowdata.compGroupId+"','"+rowdata.compGroupCode+"','"+rowdata.compGroupName+"','"+rowdata.compGroupShortname+"','"+rowdata.remark+"','"+rowdata.status+"');\" style='background:url(${ctx}/lib/img/icon/icon.png) no-repeat 0px 0px' class='opIcon' title='<spring:message code="message.jqGrid.cz.bianJi"/>'></a></ms:btn>";
                        str += "<ms:btn url='/stdCompGroup/toGroupDetail.html'><a href=\"javascript:show('"+rowdata.compGroupId+"');\" style='background:url(${ctx}/lib/img/icon/icon.png) no-repeat -100px 0px' class='opIcon' title='<spring:message code="message.jqGrid.cz.xiangQing"/>'></a></ms:btn>";
                        str += "<ms:btn url='/stdCompGroup/stdCompGroupLog.html'><a href='stdCompGroupLog.html?tid="+rowdata.compGroupId+"&compGroupCode="+rowdata.compGroupCode+"&compGroupName="+rowdata.compGroupName+"' style='background:url(${ctx}/lib/img/icon/icon.png) no-repeat -120px 0px' class='opIcon' title='<spring:message code="message.jqGrid.cz.weiHuJiLu"/>'></a></ms:btn>";
                        str += "<ms:btn url='/stdCompGroup/stdCompGroupSubC.html'><a href='stdCompGroupSubC.html?tid="+rowdata.compGroupId+"' style='background:url(${ctx}/lib/img/icon/icon.png) no-repeat -160px 0px' class='opIcon' title='<spring:message code="message.jqGrid.cz.xiaShuQiYeGuanLi"/>'></a></ms:btn>";
                        return str;
                    }
                    },
                    { name: 'compGroupId', align: 'center', hidden:true, width: 80,sortable: false},
                    { name: 'compGroupCode', align: 'center',width: 80,sortable: false},
                    { name: 'compGroupName', align: 'center' ,width: 150,sortable: false},
                    { name: 'compGroupShortname', align: 'center',width: 70,sortable: false},
                    { name: 'remark', align: 'center',width: 80,sortable: false},
                    { name: 'status', align: 'center',width: 40,sortable: false,
                        cellattr:function (rowId, val, rawObject, cm) {
                            if(val == '停用'){
                                return 'style="color:red"';
                            }
                        },
                        formatter:function(cellvalue, options, row){
                            if(cellvalue==1){ 
                                return "<spring:message code="message.button.start"/>"; 
                                }else{
                                    return "<spring:message code="message.button.stop"/>"; 
                                    }
                            }
                    }
                ],
                rowNum: 20,
                rowList: [10, 20, 50, 100],
                rownumbers: true,
                pager: "#gridpage",
                viewrecords: true,
                multiselect: true, 
                caption: "<spring:message code="message.list.compgroupStdlist"/>",
                 //序号宽度自动变化
                gridComplete:function(){
                    //序号列宽度自适应（参数为jqgridID）
                    autoRNWidth("gridlist");
                    //数据只有一条时默认选中（参数为jqgridID）
                    selectByOneData("gridlist");
                },
                jsonReader: {
                    repeatitems: false,
                    id: "compGroupId"
                }
            });
            $("#gridlist").jqGrid('navGrid', '#gridpage', { add: false, edit: false, del: false, search: false, refresh: false });
        });

       
        function edit(id){
             $.HN.dialog.open({
                 id:"edit",
                 title:"<spring:message code="message.lable.compgroupSTDedit"/>",
                 url:" ${ctx}/stdCompGroup/compGroupEdit.html?cg="+id,
                 width:"800px",
                 height:"300px"
             });
         
             //location="compGroupEdit.html?cg="+id;
        }
        
        function show(id){
         location="toGroupDetail.html?tid="+id;
       }
        //tingyong
        function batchChangeStatus(status) {
                var msg = "<spring:message code="message.button.stop"/>";
                var url = "${ctx}/stdCompGroup/enable.html";
                if(status == 1){
                    msg = "<spring:message code="message.button.start"/>";
                    url = "${ctx}/stdCompGroup/disable.html";
                }
            var rowIds = $("#gridlist").jqGrid("getGridParam", "selarrrow") || [];
            if (rowIds.length <= 0) {
                $.alert("<spring:message code="message.lable.pleaseSelect"/>"+msg+"<spring:message code="message.lable.de"/><spring:message code="message.listForm.jiTuan"/>！", "warn");
                return;
            }
            // -----begin
            var data = "";
            var list = [];
            for(var i = 0;i<rowIds.length;i++){
                var sta =  $("#gridlist").jqGrid('getRowData',rowIds[i]);
                if(sta.status != msg){
                    var compGroupName = sta.compGroupName;
                    
                    data += compGroupName+"<br/>";
                    list.push({"compGroupId":rowIds[i], "status":status});
                }else{
                    
                }  
            }
            if(data){
                data = data.substring(0,data.length-1);
            }else{
                $.alert("<spring:message code="message.lable.ninXuanZe"/><spring:message code="message.listForm.jiTuan"/><spring:message code="message.lable.yiJingShi"/>"+msg+"<spring:message code="message.lable.zhuangTaiGTH"/>", "warn");
                return;
            }
            // -----end
            
          //获取选中的ID及对应的名字（参数:jqgridId,名字列名，状态列名，当前操作即列表中显示的值），返回infos[0]是ID串，infos[1]是名字串
            var infos = batchSwitchStatus("gridlist","compGroupName","status",msg,"<spring:message code='message.listForm.jiTuanMingCheng'/>");
            if ( !(infos instanceof Array)){
                return;
            }
            
            $.HN.message.confirm('<spring:message code="message.lable.OKYES"/>'+msg+'<spring:message code="message.lable.yiXia"/><spring:message code="message.listForm.jiTuan"/><spring:message code="message.lable.ma"/><br/>'+infos[1].replace(/\,/g,"<br/>"), '', '').on(function (e) {
                if (e) {
            $.post(url, {
                "array" : json.jsonToString(list)
            }, function(result) {
                if (result.success) {
                    $.alert("<spring:message code="message.HN.alert.chengGong"/>"+msg+result.conditions.sum+"<spring:message code="message.lable.tiao"/>！", "success");
                    $("#gridlist").trigger("reloadGrid");
                } else {
                    $.alert(result.msg || msg+"<spring:message code="message.HN.alert.shibai"/>！", "error");
                }
            }, "json");
                }
            });
            }
        ///////////////////////////////////
        function CurentTime(now)  
        {                    
            var year = now.getFullYear();   
            var month = now.getMonth() + 1; 
            var day = now.getDate();     
                 
            var hh = now.getHours();       
            var mm = now.getMinutes(); 
            var ss=now.getSeconds(); 
            var clock = year + "-"; 
            if(month < 10) clock += "0";         
            clock += month + "-";  
            if(day < 10) clock += "0";   
            clock += day + " "; 
            if(hh < 10) clock += "0";  
            clock += hh + ":";  
            if (mm < 10) clock += '0';   
            clock += mm+ ":";  
            if (ss < 10) clock += '0';   
            clock += ss;  
            return(clock);   
        }
        
        //导出
         function exportExcel(){
        	 $("#exportExcel").submit();
        } 
        
        
        
         /* 新增弹窗 */
        $('#addNew').click(function () {
            $('.modal-title').html('<spring:message code="message.lable.compgroupSTDadd"/>');
            id="";
            status="";
            $('#compGroupCode').val("");
            $('#compGroupName').val("");
            $('#compGroupShortname').val("");
            $('#remark').val("");
            $('#exampleModal').modal({
                keyboard: true
            });
        });
        
        /* 编辑弹窗 */
        function edit(compGroupId,compGroupCode,compGroupName,compGroupShortname,remark,status){
            id = compGroupId;
            status=status;
            $('.modal-title').html('<spring:message code="message.lable.compgroupSTDedit"/>&nbsp;'+compGroupCode);
            $('#compGroupCode').val(compGroupCode);
            $('#compGroupName').val(compGroupName);
            $('#compGroupShortname').val(compGroupShortname);
            $('#remark').val(remark);
            $('#exampleModal').modal({
                 keyboard: true
             });
            }
        
        
        
          /* 保存弹窗新增编辑 */
        function save(){
        	 if (!validate()) {
                 return;
                }
             var compGroupCode = $("#compGroupCode").val();
             var compGroupName = $("#compGroupName").val();
             var compGroupShortname = $("#compGroupShortname").val();
             var remark = $("#remark").val();
             $.HN.message.confirm('<spring:message code="message.HN.alert.OkSaveYESorNO"/>', '', '').on(function (e) {
                if (e) {
                    var url = "${ctx}/stdCompGroup/add.html";
                    if(id !=null && id != ""){      
                        url = "${ctx}/stdCompGroup/edit.html";      
                        }
                    $.ajax({
                       type: "POST",
                       url: url,
                       data: {
                           compGroupCode:compGroupCode,
                           compGroupName:compGroupName,
                           compGroupShortname:compGroupShortname,
                           remark:remark,
                           compGroupId:id,
                           status:status},
                       dataType:"json",
                       success: function(result){
                           if(result.success){
                        	   if(id !=null && id != ""){
                        		   $.alert("<spring:message code="message.HN.alert.success"/>", "success");
                        	   }else{
                        		   $.alert("为您新增一条编码为"+result.msg+"的集团", "success");
                        	   }
                            $("#gridlist").trigger("reloadGrid");
                            $('#exampleModal').modal('hide');
                           }else{
                            $.alert(result.msg || "<spring:message code="message.HN.alert.fail"/>", "error");
                               }
                           }
                    });
                }
            });
        }
        
        function validate() {
        	 var groupId=$.trim($('#compGroupId').val());
            // var groupCode=$.trim($('#compGroupCode').val());
             var groupName=$.trim($('#compGroupName').val());
             var groupShortname=$.trim($('#compGroupShortname').val());
             var remark=$.trim($('#remark').val());
             

	       /*    if(groupCode==""){
	                 $.alert("<spring:message code="message.yanZheng.qingShuRu"/><spring:message code="message.listForm.jiTuanBianMa"/>", "warn");
	                 return ;
	           }else if (!/^\d+$/.test(groupCode)) {
	                  $.alert("<spring:message code="message.listForm.jiTuanBianMa"/><spring:message code="message.yanZheng.zhiNengYouZiMuShuZiZuCheng"/>", "warn");
	                  return  false;
	           }else if (groupCode.length>36){
	                  $.alert("<spring:message code="message.listForm.jiTuanBianMa"/><spring:message code="message.info.zuiDaChangDu"/>36<spring:message code="message.info.geZiFu"/>", "warn");
	                  return  false;
	           } */
             
	        
	            if(groupName==""){
	                 $.alert("<spring:message code="message.yanZheng.qingShuRu"/><spring:message code="message.listForm.jiTuanMingCheng"/>", "warn");
	                 return ;
	            }else if (groupName.length>170){
	                $.alert("<spring:message code="message.listForm.jiTuanMingCheng"/><spring:message code="message.info.zuiDaChangDu"/>170<spring:message code="message.info.geZiFu"/>", "warn");
	                return  false;
	            }
	            
	            
	            if(groupShortname==""){
	              
	            }else if (groupShortname.length>85){
	                $.alert("<spring:message code="message.listForm.jiTuanJianCheng"/><spring:message code="message.info.zuiDaChangDu"/>85<spring:message code="message.info.geZiFu"/>", "warn");
	                return  false;
	            }
	            
		        
		         if (remark == null || remark == "") {
		             
		         }else if(remark.length>341){
		             $("#remark").trigger("focus");
		             $.alert("<spring:message code="message.lable.remark"/><spring:message code="message.info.zuiDaChangDu"/>341<spring:message code="message.info.geZiFu"/>！", "warn");
		             return false;;
		         } 
	         
	            return true;
        }
        
        
        
    </script>
</body>
</html>